<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="com.alibaba.aliper.server.model.interfaces.AliperView"%>
<%@page import="com.alibaba.aliper.server.model.interfaces.AgentView"%>
<%@page import="com.alibaba.aliper.server.model.interfaces.ChartView"%>
<%@page import="com.alibaba.aliper.server.model.impl.AliperServer"%>
<%@page import="com.alibaba.aliper.server.model.interfaces.LineView"%>
<%
	AliperView aliper = AliperServer.getAliperServer();
%>


<%@page import="com.alibaba.aliper.server.model.domain.Point"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>阿里巴巴平台测试开发部性能实时监控平台</title>
<script type="text/javascript" src="sources/ajax.js"></script>
<script type="text/javascript" src="sources/jscharts.js"></script>
<script type="text/javascript" src="sources/aliper.js"></script>
</head>
<body>
<h1>监控平台</h1>
<%
	int index = 0;
	for(AgentView agent : aliper.getAgents()){
%>
<h2><%=agent.getId()%></h2>
<table>
<tr>
<%
	for(ChartView chart : agent.getCharts()){
%>
<td>
<div id="<%=agent.getId()%>_<%=chart.getId()%>_div">Loading graph...</div>

<script type="text/javascript">
<%		String chartName = "chart_"+(index++);
%>
var <%=chartName%> = new AliperChart("<%=agent.getId()%>_<%=chart.getId()%>_div","<%=agent.getId()%>","<%=chart.getId()%>");
<%
		LineView[] lines = chart.getLines();
		for(LineView line : lines){
%>
<%=chartName%>.addLine("<%=line.getId()%>");
<%
		}
		%>
<%=chartName%>.starty = null;
<%=chartName%>.lengthy = null;
		<%
	    if(lines.length == 1){
	    	if(lines[0].isRangeAvailable()){
	    		%>
<%=chartName%>.starty = <%=lines[0].getRangeMin()%>;
<%=chartName%>.lengthy = <%=lines[0].getRangeMax() - lines[0].getRangeMin()%>;
	    			    		<%
	    			
	    	}
	    	Point first = lines[0].getFirstPoint();
  	      if( first != null){
%>
<%=chartName%>.startx = <%=first.getX()%>;
<%
  	        }
	    } 
%>
<%=chartName%>.show();
</script>
</td>
			
			<%			
		}
%>
</tr>
</table>
<%
	}
%>


</body>
</html>